<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>Hello APP</title>
    <link rel="stylesheet" type="text/css" href="./css/api.css" />
    <style type="text/css">
    html,body{
        height: 100%;
    }
    #wrap{
        height: 100%;
        display: -webkit-box;
        display: -webkit-flex;
        display: flex;
        -webkit-box-orient: vertical;
        -webkit-flex-flow: column;
               flex-flow: column;
    }
    #header{
        text-align: center; background-color: #81a9c3; color: #fff;
        width: 100%;
    }
    #header h1{
        font-size: 20px; height: 44px; line-height: 44px; margin: 0em; color: #fff;
    }
    #main{
        -webkit-box-flex: 1;
        -webkit-flex: 1;
        flex: 1;
    }
    #footer{
        height: 30px; line-height: 30px;
        background-color: #81a9c3;
        width: 100%;
        text-align: center;
    }
    #footer h5{
        color: white;
    }
    .con{font-size: 28px; text-align: center;}
    .flex-con{
      overflow: auto
    }
    </style>
</head>
<body>
    <div id="wrap">
        <div id="header">
            <h1>APICloud</h1>
        </div>
        <div id="main" class="flex-con">

			<div class="clickbtn" tapmode="active" onclick="qb_splash()">qb_splash</div>
			<div class="clickbtn" tapmode="active" onclick="qb_interaction()">qb_interaction</div>
			<div class="clickbtn" tapmode="active" onclick="qb_banner()">qb_banner</div>
			<div class="clickbtn" tapmode="active" onclick="qb_native()">qb_native</div>
			<div class="clickbtn" tapmode="active" onclick="qb_native1()">qb_native1</div>
			<div class="clickbtn" tapmode="active" onclick="qb_native2()">qb_native2</div>
			<div class="clickbtn" tapmode="active" onclick="qb_native3()">qb_native3</div>
	
			<div class="clickbtn" tapmode="active" onclick="qb_rewardvideo_playNow()">qb_rewardvideo_playNow</div>
			<div class="clickbtn" tapmode="active" onclick="qb_expressdrawfeed()">qb_expressdrawfeed</div>
	
			<div class="clickbtn" tapmode="active" onclick="qb_removeViewById()">qb_removeViewById</div>

        </div>
        <div id="footer">
            <h5>Copyright &copy;<span id="year"></span> </h5>
        </div>
    </div>
</body>
<script type="text/javascript" src="./script/api.js"></script>
<script type="text/javascript">

    var modulequbian = null;

    apiready = function(){
        modulequbian = api.require('moduleQubian');

		console.log("Hello APICloud");

        var header = $api.byId('header');
        //适配iOS 7+，Android 4.4+状态栏
        $api.fixStatusBar(header);

        var headerPos = $api.offset(header);
        var main = $api.byId('main');
        var mainPos = $api.offset(main);
        /*
        api.openFrame({
            name: 'main',
            url: 'html/main.html',
            bounces: true,
            rect: {
                x: 0,
                y: headerPos.h,
                w: 'auto',
                h: mainPos.h
            }
        });
        */

        var year = $api.byId('year');
        year.innerHTML = new Date().getFullYear();

    };

    function qb_splash(){
		//var param = {codeId:"1330512946933022784", frameName:"index", fixed:true};
		var param = {codeId:"1330512946933022784"};
        //w、h传0或者不传（单位dp）：宽度和高度默认占满
		modulequbian.qb_splash(param, function(ret){
			var id = ret.id;
			var tag = ret.tag;
			var msg = ret.msg;
			if(-1 == tag){
				//请求错误
				api.toast({msg:msg});
				//请求失败后，需要删除布局上的填充view
				qb_removeViewById(id);
			}else if(0 == tag){
			 	//被关闭
                api.toast({msg:msg});
				//请求成功后被关闭，也需要删除布局上的填充view
				qb_removeViewById(id);
			}else if(1 == tag){
				//请求成功并展现
				api.toast({msg:msg});
			}else if(2 == tag){
				//被点击
				api.toast({msg:msg});
			}else if(3 == tag){
				//激励视频发送奖励（仅激励视频有此回调）
				api.toast({msg:msg});
			}
		});
	}

    //插屏
	function qb_interaction(){
		var param = {codeId:"1330513058157576258"};
		modulequbian.qb_interaction(param, function(ret){
			var tag = ret.tag;
			var msg = ret.msg;
			if(-1 == tag){
				//请求错误
				api.toast({msg:msg});
			}else if(0 == tag){
				//被关闭
				api.toast({msg:msg});
				//释放资源
				qb_destroyInteractionAll();
			}else if(1 == tag){
				//请求成功并展现
				api.toast({msg:msg});
			}else if(2 == tag){
				//被点击
				api.toast({msg:msg});
			}else if(3 == tag){
				//激励视频发送奖励（仅激励视频有此回调）
				api.toast({msg:msg});
			}
		});
	}

	function qb_banner(){
		var param = {codeId:"1330513198897446943"};
		modulequbian.qb_banner(param, function(ret){
			var id = ret.id;
			api.toast({msg:id});
			var tag = ret.tag;
			var msg = ret.msg;
			if(-1 == tag){
				//广告请求错误
				api.toast({msg:msg});
			}else if(0 == tag){
				//广告被关闭
				api.toast({msg:msg});
			}else if(1 == tag){
				//广告请求成功并展现
				api.toast({msg:msg});
			}else if(2 == tag){
				//广告被点击
				api.toast({msg:msg});
			}else if(3 == tag){
				//激励视频广告发送奖励（仅激励视频广告有此回调）
				api.toast({msg:msg});
			}
		});
	}

    //信息流
	function qb_native(){
		var param = {codeId:"1330513366195650582", fixed:true, x:0, y:0, w:0, h:0};
        //w：原生view的宽度（单位：dp），默认450（dp）
        //h：原生view的高度（单位：dp）
        //x：原生view距离屏幕左边的距离（单位：dp）
        //y：原生view距离屏幕顶端的距离（单位：dp）
		modulequbian.qb_native(param, function(ret){
			var id = ret.id;
			var tag = ret.tag;
			var msg = ret.msg;
			if(-1 == tag){
				//请求错误
				api.toast({msg:msg});
				//删除布局view
				qb_removeViewById(id);
			}else if(0 == tag){
				//被关闭
				api.toast({msg:msg});
				//删除布局view
				//qb_removeViewById(id);
				//释放资源
				//qb_destroyFeedAll();
			}else if(1 == tag){
				//请求成功并展现
				api.toast({msg:msg});
			}else if(2 == tag){
				//被点击
				api.toast({msg:msg});
			}else if(3 == tag){
				//激励视频发送奖励（仅激励视频有此回调）
				api.toast({msg:msg});
			}
		});
	}

	function qb_native1(){
		var param = {codeId:"1330513366195650582", fixed:true, x:0, y:100, w:0, h:0};
        //w：原生view的宽度（单位：dp），默认450（dp）
        //h：原生view的高度（单位：dp）
        //x：原生view距离屏幕左边的距离（单位：dp）
        //y：原生view距离屏幕顶端的距离（单位：dp）
		modulequbian.qb_native(param, function(ret){
			var id = ret.id;
			var tag = ret.tag;
			var msg = ret.msg;
			if(-1 == tag){
				//请求错误
				api.toast({msg:msg});
				//删除布局view
				qb_removeViewById(id);
			}else if(0 == tag){
				//被关闭
				api.toast({msg:msg});
				//删除布局view
				qb_removeViewById(id);
				//释放资源
				qb_destroyFeedAll();
			}else if(1 == tag){
				//请求成功并展现
				api.toast({msg:msg});
			}else if(2 == tag){
				//被点击
				api.toast({msg:msg});
			}else if(3 == tag){
				//激励视频发送奖励（仅激励视频有此回调）
				api.toast({msg:msg});
			}
		});
	}

	function qb_native2(){
		var param = {codeId:"1330513366195650582", fixed:true, x:100, y:200, w:0, h:0};
        //w：原生view的宽度（单位：dp），默认450（dp）
        //h：原生view的高度（单位：dp）
        //x：原生view距离屏幕左边的距离（单位：dp）
        //y：原生view距离屏幕顶端的距离（单位：dp）
		modulequbian.qb_native(param, function(ret){
			var id = ret.id;
			var tag = ret.tag;
			var msg = ret.msg;
			if(-1 == tag){
				//请求错误
				api.toast({msg:msg});
				//删除布局view
				qb_removeViewById(id);
			}else if(0 == tag){
				//被关闭
				api.toast({msg:msg});
				//删除布局view
				qb_removeViewById(id);
				//释放资源
				qb_destroyFeedAll();
			}else if(1 == tag){
				//请求成功并展现
				api.toast({msg:msg});
			}else if(2 == tag){
				//被点击
				api.toast({msg:msg});
			}else if(3 == tag){
				//激励视频发送奖励（仅激励视频有此回调）
				api.toast({msg:msg});
			}
		});
	}

    function qb_native3(){
		var param = {codeId:"1330513366195650582", fixed:false, x:100, y:300, w:0, h:0};
        //w：原生view的宽度（单位：dp），默认450（dp）
        //h：原生view的高度（单位：dp）
        //x：原生view距离屏幕左边的距离（单位：dp）
        //y：原生view距离屏幕顶端的距离（单位：dp）
		modulequbian.qb_native(param, function(ret){
			var id = ret.id;
			var tag = ret.tag;
			var msg = ret.msg;
			if(-1 == tag){
				//请求错误
				api.toast({msg:msg});
				//删除布局view
				qb_removeViewById(id);
			}else if(0 == tag){
				//被关闭
				api.toast({msg:msg});
				//删除布局view
				qb_removeViewById(id);
				//释放资源
				qb_destroyFeedAll();
			}else if(1 == tag){
				//请求成功并展现
				api.toast({msg:msg});
			}else if(2 == tag){
				//被点击
				api.toast({msg:msg});
			}else if(3 == tag){
				//激励视频发送奖励（仅激励视频有此回调）
				api.toast({msg:msg});
			}
		});
	}

    //在线加载并播放激励视频
	function qb_rewardvideo_playNow(){
		// userID 用户ID，服务器给服务器回调时需要（可不填）
        // callExtraData 服务器回调额外信息（可不填）
		var param = {codeId:"1330515047692124225", userId:"zhansan", callExtraData:""};
		modulequbian.qb_rewardvideo_playNow(param, function(ret){
			var tag = ret.tag;
			var msg = ret.msg;
			if(-1 == tag){
				//请求错误
				api.toast({msg:msg});
				//释放资源
				qb_destroyRewardVideoAll();
			}else if(0 == tag){
				//被关闭
				api.toast({msg:msg});
				//释放资源
				qb_destroyRewardVideoAll();
			}else if(1 == tag){
				//请求成功并展现
				var orderNo = ret.orderNo;//服务器回调需要使用的相关参数
				api.toast({msg:msg});
			}else if(2 == tag){
				//被点击
				api.toast({msg:msg});
			}else if(3 == tag){
				//激励视频发送奖励（仅激励视频有此回调）
				api.toast({msg:msg});
			}
		});
	}

    //draw信息流
	function qb_expressdrawfeed(){
		var param = {codeId:"1330515190466232331", fixed:true, x:0, y:0, w:0, h:0};
        //w、h传0或者不传（单位dp）：宽度和高度默认占满
		modulequbian.qb_expressdrawfeed(param, function(ret){
			var id = ret.id;
			var tag = ret.tag;
			var msg = ret.msg;
			if(-1 == tag){
				//请求错误
				api.toast({msg:msg});
				//删除布局view
				qb_removeViewById(id);
			}else if(0 == tag){
				//被关闭
				api.toast({msg:msg});
				//删除布局view
				qb_removeViewById(id);
			}else if(1 == tag){
				//请求成功并展现
				api.toast({msg:msg});
			}else if(2 == tag){
				//被点击
				api.toast({msg:msg});
			}else if(3 == tag){
				//激励视频发送奖励（仅激励视频有此回调）
				api.toast({msg:msg});
			}
		});
	}



    //移动位置
    function qb_moveViewById(id){
		var param = {id:id, x:100, y:300};//id不能为空，否则无效
		modulequbian.qb_moveViewById(param);
	}

	//删除指定内容或者最近一条内容
	function qb_removeViewById(id){
		var param = {id:id};
        //id编号，删除指定内容。不传默认删除最近的一条内容
		modulequbian.qb_removeViewById(param);
	}

	//释放所有资源
	function qb_destroyAll(){
		var param = {};
		modulequbian.qb_destroyAll(param);
	}

	//释放插屏资源
	function qb_destroyInteractionAll(){
		var param = {};
		modulequbian.qb_destroyInteractionAll(param);
	}

	//释放激励视频资源
	function qb_destroyRewardVideoAll(){
		var param = {};
		modulequbian.qb_destroyRewardVideoAll(param);
	}

	//释放信息流资源
	function qb_destroyFeedAll(){
		var param = {};
		modulequbian.qb_destroyFeedAll(param);
	}

</script>
</html>
